package createArff;

import Types.Sentence;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.LinkedList;
import java.util.List;
import readData.Reading;

public class AddInstanceToFile {

    public void Reading() {
        ////First reading all sentences from files....
        try {
            Reading read = new Reading();
            ///reading from drug bank
            List<Sentence> sent = read.returnAllSent();
            List<String> vect = new LinkedList<String>();
            for (int i = 0; i < 10; i++) {
                vect.add(ConvertToVector(sent.get(i)));
            }
            /////writing in file
            WriteIntoFile(vect);

        } catch (Throwable t) {
        }
    }

    String ConvertToVector(Sentence sent) {
        FeaturesForSVM fea = new FeaturesForSVM();
        return fea.ReturnVector(sent);
    }

    void WriteIntoFile(List<String> vect) {
        try {
            BufferedWriter wr = new BufferedWriter(new FileWriter(new File("bin/arff/out.arff")));
            WritingFirstPart(wr);
            for (int i = 0; i < vect.size(); i++) {
                wr.write(vect.get(i));
                wr.write("\n");
            }
            wr.close();
        } catch (Throwable t) {
        }
    }

    void WritingFirstPart(BufferedWriter wr) {
        try {
            wr.write("%");
            wr.write("\n");
            wr.write("% Summary Statistics:");
            wr.write("\n");
            wr.write("%  	           Min  Max   Mean    SD   Class Correlation");
            wr.write("\n");
            wr.write("%    sepal length: 4.3  7.9   5.84  0.83    0.7826   ");
            wr.write("\n");
            wr.write("%     sepal width: 2.0  4.4   3.05  0.43   -0.4194");
            wr.write("\n");
            wr.write("%    petal length: 1.0  6.9   3.76  1.76    0.9490  (high!)");
            wr.write("\n");
            wr.write("%     petal width: 0.1  2.5   1.20  0.76    0.9565  (high!)");
            wr.write("\n");
            wr.write("% ");
            wr.write("\n");
            wr.write("% 9. Class Distribution: 33.3% for each of 3 classes.");
            wr.write("\n");
            wr.write("@RELATION iris");
            wr.write("\n");
            wr.write("@ATTRIBUTE sepallength	string");
            wr.write("\n");
            wr.write("@ATTRIBUTE sepalwidth 	REAL");
            wr.write("\n");
            wr.write("@ATTRIBUTE petallength 	REAL");
            wr.write("\n");
            wr.write("@ATTRIBUTE petalwidth	REAL");
            wr.write("\n");
            wr.write("@ATTRIBUTE class 	{Iris-setosa,Iris-versicolor,Iris-virginica}");
            wr.write("\n");
            wr.write("@DATA");
            wr.write("\n");
        } catch (Throwable t) {
        }
    }
}
